package spring.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
//控制器注解，springMVC 会自动扫描该注解

public class DemoController {
    //@RequestMapping控制访问路径注解
    @RequestMapping("/demo1")
    public String demo1(){
        return "/demo1.jsp";//默认请求转发
    }

    public String demo2(HttpServletResponse response){
        return "redirect:/demo1.jsp";//在返回路径字符串中使用redirect:前缀则springMVC自动使用重定向方式进行跳转
    }


    //想要把请求数据弄过来
    @RequestMapping("/demo3")
    public ModelAndView demo3(){
        Map<String,Object> model = new HashMap<String,Object>(){{
            put("user_name","admin");
            put("password","123456");
        }};

        ModelAndView modelAndView = new ModelAndView("demo1.jsp",model);

        return modelAndView;
    }
}
